/*  J
**  Date 2007-06-03 19:23:55 
**  File debug.c  v 1.0
**  Author Mucker
**  See Copyright Notice in J.h
**  
*/

#include "J.h"

#include "debug.h"
#include "lex.h"

/*
** output file
** {{-----------------------------------------------------------
*/


/*
** }}-----------------------------------------------------------
*/

void lex_output(lex_state *ls)
{
    FILE *fp;
    char fmt[200];
    printf("%c", &ls->current);
    fp = fopen("./outd.obj", "w");
	//fp = stdout;
    fprintf(fp, "\r\nline :  1 ");
	fflush(fp);
    while(ls->current != EOF){
        int line = ls->line;
        int c = lex(ls, &ls->t.info);
        if( c > 0 ) {
            switch(c){
                case K_NUMBER:
                    fprintf(fp,  "\r\n\t[ %f , %s]\t", ls->t.info.num,"*");
					fflush(fp);
                    break;
                case K_NAME:{

                    Jstring *js;
                    js = ls->t.info.str;
                    js = js+1;
                    fprintf(fp, "\r\n\t[ %s , %s]\t", js, "*");
					fflush(fp);
                   break;
                }
                case K_STRING:{
                    Jstring *js;
                    js = ls->t.info.str;
                    js = js+1;
                    fprintf(fp, "\r\n\t[ %s , %s]\t", js, "*");
					fflush(fp);
                    break;
                }
                default :
                    fprintf(fp, "\r\n\t[ %s , %s]\t", "*", "*");
					fflush(fp);
            }
        }
        else{
            fprintf(fp, "\r\n\t%c\t", c);
 			fflush(fp);
       }
   }
    fclose( fp);
}